home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / source / music4c.sit / Music4C Folder / SFConvert folder / interleavedTo.c < prev    next >
C/C++ Source or Header  |  1990-06-24  |  3KB  |  135 lines

  1. #include    "SFConvert.h"
  2. #include    <stdio.h>
  3. #include    <unix.h>
  4. #include    <string.h>
  5. #include    <math.h>
  6. #include    <SANE.h>
  7. #include    "SDtype.h"
  8.  
  9.  
  10.  
  11. extern    long        TotalSamps;
  12. extern    CursHandle    watchCurs;
  13. extern    long        SampleRate;
  14. extern    double        MaxSample;
  15. extern    double        MinSample;
  16. extern    long        fileSize;
  17. extern    ioParam        myIOParmBlk;
  18. extern    ioParam        NewParmBlk;
  19. extern    int            SFOUTPUTtype;    
  20. extern    Boolean        SDnoResource;
  21. extern    OSErr        theErr;
  22. extern    long        RecLength;
  23. extern    int            nrec;    
  24.  
  25.  
  26. void    DoOSErrorAlert(Str255, Str255);
  27.  
  28. Boolean    InterleavedToSD1(void);
  29. Boolean    InterleavedToSD2(void);
  30. Boolean    InterleavedToCHUNKY(void);
  31. Boolean    InterleavedToAIFF(void);
  32. Boolean    InterleavedToFloat(void);
  33.  
  34.  
  35. Boolean    InterleavedToSD1()
  36. {
  37.     return(FALSE);
  38. }
  39. Boolean    InterleavedToSD2()
  40. {
  41.     return(FALSE);
  42. }
  43. Boolean    InterleavedToCHUNKY()
  44. {
  45.     return(FALSE);
  46. }
  47. Boolean    InterleavedToAIFF()
  48. {
  49.     return(FALSE);
  50. }
  51. Boolean    InterleavedToFloat()
  52. {
  53.     register    long    i;
  54.     register    double    offset;
  55.     register    double    scalefactor;
  56.     register    double    x;
  57.     Str255    mess;
  58.     unsigned    int        *theIbuf, *Iptr;
  59.     float        *sp, *SampBuf;
  60.     long        nBytes;
  61.     long        nSamps;
  62.     long        bytesLeft;
  63.     long        sampBufsz;
  64.  
  65.     
  66.     
  67.     RecLength = (long)(16384);
  68.     nrec = 0;
  69.     SetProgressDialog();
  70.  
  71.     TotalSamps =  fileSize / sizeof(int);
  72.     
  73.     sampBufsz  = RecLength  / sizeof(float);
  74.     theIbuf = (unsigned int *)NewPtr(sizeof(int) * sampBufsz);
  75.     SampBuf = (float *)NewPtr( sizeof(float) * sampBufsz);
  76.     
  77.     
  78.     offset = fabs(MinSample);
  79.     scalefactor = SAMPMAX / (offset + MaxSample);
  80.  
  81.     bytesLeft = fileSize;
  82.  
  83.     myIOParmBlk.ioPosMode = fsAtMark;
  84.     myIOParmBlk.ioPosOffset = NIL;
  85.  
  86.     NewParmBlk.ioPosMode = fsAtMark;
  87.     NewParmBlk.ioPosOffset = NIL;
  88.  
  89.  
  90.     while ( bytesLeft > 0L ) {
  91.         if ( bytesLeft > RecLength )
  92.             nBytes = RecLength;
  93.         else
  94.             nBytes = bytesLeft;
  95.             
  96.         myIOParmBlk.ioBuffer = (Ptr)theIbuf;
  97.         myIOParmBlk.ioReqCount = nBytes;
  98.         theErr = PBRead(&myIOParmBlk, FALSE);
  99.         if (theErr != noErr ) {
  100.             if ( theErr == eofErr )
  101.                 DoOSErrorAlert("\pEnd of file reached in read form MACread_set", NIL);
  102.         }
  103.         nBytes = myIOParmBlk.ioActCount;
  104.         nSamps = nBytes / sizeof(int);
  105.         for ( i = 0, Iptr = theIbuf, sp = SampBuf; i < nSamps; i++ ) {
  106.             *sp++ = ((*Iptr++ + offset ) * scalefactor);
  107.         }
  108.  
  109. /* write it out */
  110.         NewParmBlk.ioReqCount = (long)(nSamps * sizeof(float));
  111.         NewParmBlk.ioBuffer = (Ptr)SampBuf;
  112.         if ( (theErr = PBWrite(&NewParmBlk, FALSE)) != noErr ) { 
  113.             DoOSErrorAlert("\pError writing to sample file", NIL);
  114.         }
  115.         if ( NewParmBlk.ioActCount != (long)(nSamps * sizeof(float)) ) {
  116.             DoOSErrorAlert("\pError writing to sample file, wrote wrong number of bytes", NIL);
  117.         }
  118.  
  119.         nrec++;
  120.         if ( !UpdateProgressDialog() ) {
  121.             DisposPtr((Ptr)SampBuf);
  122.             DisposPtr((Ptr)theIbuf);
  123.             DisposeProgDialog();
  124.             InitCursor();
  125.             return(FALSE);
  126.         }
  127.         bytesLeft -= nBytes;
  128.     }
  129.     DisposPtr((Ptr)SampBuf);    
  130.     DisposPtr((Ptr)theIbuf);    
  131.     DisposeProgDialog();
  132.     InitCursor();
  133.     return(TRUE);
  134. }
  135.